<script type="text/javascript">
    $().ready(function(){
        // Disable this while we work out how to handle the multi-rows
        $('#auth-systems-list tbody:even tr').each(function(){
            $(this).addClass('alt');

        });

        $('#auth-systems-list tbody').hover(function(){
            $(this).children('tr').addClass('over');

        }, function(){
            $(this).children('tr').removeClass('over');
        });

        $('#auth-systems-list').each(function(){
            /**
             * If the page (well content area) is too small to display the
             * system list properly  then - force the size of the page to
             * accomidate the system list
             * (this should force horizontal scrolling)
             */
            if ($(this).parent().width() < $(this).width()) {
                $(this).parent().width($(this).width());
            }
        });

    });
</script>


<?php if ($rootDomainCollection): ?>
    <h1><?php echo $pageTitle ?></h1>

<?php if ($domainRelationList->count() > 0): ?>
        <table id="auth-systems-list">
            <thead>
                <tr>
                    <th>
                        Information Domain Name
                    </th>
                    <th>
                        Business Owner(s)
                    </th>
                    <th>
                        Has
                    </th>
                    <th>
                        Related System
                    </th>
                    <th>
                        System Owner(s)
                    </th>
            <?php foreach ($rootDomainCollection->getCompressedPropertyValueArrayForIdentifiers(sfConfig::get($systemPropertySearchKey), true) as $displayPropertyName => $displayPropertyValue): ?>
                <th>
                <?php echo $displayPropertyName ?>
            </th>
            <?php endforeach ?>
                <th>
                    &nbsp;
                </th>
            </tr>
        </thead>

    <?php foreach ($domainRelationList as $informationDomainRelation): ?>
                    <tbody>
        <?php $firstRow = true ?>
        <?php $informationDomain = $informationDomainRelation->getRelatedItem(); ?>
        <?php $domainSystemRelations = $informationDomain->getRelationsByIdentifierArray(sfConfig::get($domainSystemSearchKey)); ?>
        <?php if ($domainSystemRelations->count() > 0): ?>
        <?php foreach ($domainSystemRelations as $domainSystemRelation): ?>
                            <tr <?php echo in_array($domainSystemRelation->getRelationType()->getTypeValue(), sfConfig::get('app_domains_authoritative_system_relation_types')) ? 'class="authoritative"' : '' ?> >
            <?php if ($firstRow): ?>
                                <td rowspan="<?php echo $domainSystemRelations->count() ?>">


                                    <a href="<?php echo url_for('domainViewDetails', array('uin' => $informationDomain->getUin())) ?>"><?php echo $informationDomain->getCollectionName() ?></a>
                                </td>
                                <td rowspan="<?php echo $domainSystemRelations->count() ?>">
                <?php foreach ($informationDomain->getRelationsByIdentifierArray(sfConfig::get('app_list_owner_relation_types')) as $domainOwnerRelation): ?>
                                    <p><?php echo $domainOwnerRelation->getRelatedItem()->getCollectionName(); ?></p>
                <?php endforeach; ?>
                                </td>
            <?php else: ?>

            <?php endif; ?>
                                        <td>
                <?php echo $domainSystemRelation->getRelationType()->getTypeName() ?>
                                    </td>
                                    <td>
                <?php echo $domainSystemRelation->getRelatedItem()->getCollectionName() ?>
                                    </td>
                                    <td>
                <?php foreach ($domainSystemRelation->getRelatedItem()->getRelationsByIdentifierArray(sfConfig::get('app_list_owner_relation_types')) as $systemOwnerRelation): ?>
                                            <p><?php echo $systemOwnerRelation->getRelatedItem()->getCollectionName(); ?></p>
                <?php endforeach; ?>
                                        </td>
            <?php foreach ($domainSystemRelation->getRelatedItem()->getCompressedPropertyValueArrayForIdentifiers(sfConfig::get($systemPropertySearchKey), true, false) as $displayPropertyIdentifier => $displayPropertyValue): ?>
                                                <td>
                <?php echo $displayPropertyValue ? $displayPropertyValue : '&nbsp;' ?>
                                            </td>
            <?php endforeach; ?>
            <?php if ($firstRow): ?>
                                                    <td rowspan="<?php echo $domainSystemRelations->count() ?>">
                                                        <a href="<?php echo url_for('domainViewDetails', array('uin' => $informationDomain->getUin())) ?>">Details</a>
                                                    </td>
            <?php $firstRow = false ?>
            <?php endif; ?>
                                                </tr>
        <?php endforeach; ?>
        <?php else: ?>
                                                        <tr>
                                                            <td>
                                                                <a href="<?php echo url_for('domainViewDetails', array('uin' => $informationDomain->getUin())) ?>"><?php echo $informationDomain->getCollectionName() ?></a>
                                                            </td>
                                                            <td>
                <?php foreach ($informationDomain->getRelationsByIdentifierArray(sfConfig::get('app_list_owner_relation_types')) as $domainOwnerRelation): ?>
                                                            <p><?php echo $domainOwnerRelation->getRelatedItem()->getCollectionName(); ?></p>
                <?php endforeach; ?>
                                                        </td>
                                                        <td>
                                                            &nbsp;
                                                        </td>
                                                        <td>
                                                            &nbsp;
                                                        </td>
                                                        <td>
                                                            &nbsp;
                                                        </td>
            <?php foreach ($rootDomainCollection->getCompressedPropertyValueArrayForIdentifiers(sfConfig::get($systemPropertySearchKey), true) as $displayPropertyName => $displayPropertyValue): ?>
                                                                <td>
                                                                    &nbsp;
                                                                </td>
            <?php endforeach ?>
                                                                <td>
                                                                    <a href="<?php echo url_for('domainViewDetails', array('uin' => $informationDomain->getUin())) ?>">Details</a>
                                                                </td>
                                                            </tr>
        <?php endif; ?>
                                                            </tbody>
    <?php endforeach; ?>

                                                            </table>
<?php else: ?>
                                                                    <p>
                                                                        No information domains have been configured for the root collection, please check system configuration.
                                                                    </p>
<?php endif; ?>
<?php else: ?>
                                                                        <h1>No Root Domain Collection Item Found</h1>
                                                                        <p>
                                                                            The system does not have a root domain collection item configured, please check system configuration.
                                                                        </p>
<?php endif; ?>


